import { Injectable } from '@angular/core';
import { Http, URLSearchParams } from '@angular/http';
//Models
import { AuthModel } from '../models/auth.model';
//Services
import { BaseHttpService } from '../shared/services/baseHttp.service';

@Injectable()
export class ListingRiskService extends BaseHttpService {

    constructor(private http: Http) {
        super(http);
    }

    public getCompaniesBenchmark(): Promise<any[]> {
        return super.get<any[]>(this.serverUrl + 'riskratingserv/api/v1/companies/benchmark');
    }

    public getCompanies(authObj: AuthModel, filters: any, skip: number, take: number, orderBy: string, orderByAsc: boolean): Promise<any[]> {
        let params: URLSearchParams = new URLSearchParams();
        //params.append('userId', authObj.userId);
        //params.set('accountId', authObj.accountId);
        params.appendAll(this.urlEncodeObject(filters));
        params.set('skip', skip.toString());
        params.set('take', take.toString());
        params.set('getCount', 'false');
        params.set('orderBy', orderBy);
        params.set('orderAscending', orderByAsc.toString());
        
        return super.get<any[]>(this.serverUrl + 'riskratingserv/api/v1/companies', { search: params });
    }

    public getCompaniesCount(authObj: AuthModel, filters: any): Promise<number> {
        let params: URLSearchParams = new URLSearchParams();
        params.appendAll(this.urlEncodeObject(filters));
        params.set('getCount', 'true');
        
        return super.get<number>(this.serverUrl + 'riskratingserv/api/v1/companies', { search: params });
    }
}